package com.yixing.tech.wcs.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.yixing.tech.common.base.BaseResponse;
import com.yixing.tech.common.base.BusinessException;
import com.yixing.tech.common.autoline.constant.ResultStatus;
import com.yixing.tech.common.autoline.constant.TaskErrorCode;
import com.yixing.tech.common.autoline.domain.*;
import com.yixing.tech.common.hikservice.rcs.RCSResponse;
import com.yixing.tech.common.hikservice.rcs.RCSTaskCallback;
import com.yixing.tech.common.hikservice.rcs.RCSTaskRequest;
import com.yixing.tech.common.hikservice.rcs.RCSUtil;
import com.yixing.tech.common.utils.HttpClientUtil;
import com.yixing.tech.common.utils.HttpResult;
import com.yixing.tech.wcs.constant.AgvRasterTaskEnum;
import com.yixing.tech.wcs.constant.DictId;
import com.yixing.tech.wcs.constant.EntityTemplateId;
import com.yixing.tech.wcs.constant.RCSConstant;
import com.yixing.tech.wcs.domain.po.Location;
import com.yixing.tech.wcs.domain.po.SubTask;
import com.yixing.tech.wcs.domain.po.Task;
import com.yixing.tech.wcs.domain.po.TaskCallbackInterface;
import com.yixing.tech.wcs.domain.vo.TaskErrorCallbackVO;
import com.yixing.tech.wcs.service.IBoxTaskService;
import com.yixing.tech.wcs.service.ICRUDService;
import com.yixing.tech.wcs.service.ICallbackService;
import com.yixing.tech.wcs.service.ITaskService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.bson.Document;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
@Slf4j
public class CallbackService implements ICallbackService {

    @Resource
    ITaskService taskService;

    @Resource
    ICRUDService crudService;

    @Resource
    private IBoxTaskService boxTaskService;

    public static final Map<String, String> rasterOpenMap = new HashMap<>();
    public static final Map<String, String> rasterCloseMap = new HashMap<>();

    public static final Map<String, String> agvTaskMap = new HashMap<>();

    @Override
    public Object wcsTaskFinish(List<TaskFinishReq> taskFinishReqList) {
        List<WCSResponse.ResponseData> dataList = taskFinishReqList.stream().map(req -> {
            WCSResponse.ResponseData data = new WCSResponse.ResponseData();
            data.setINSTRUCTION_CODE(req.getINSTRUCTION_CODE());
            data.setSALVER_ID(req.getSALVER_ID());
            data.setSTART_LOCATION(req.getSTART_LOCATION());
            data.setEND_LOCATION(req.getEND_LOCATION());
            data.setSUCCESS(ResultStatus.SUCCESS);
            data.setMSG("");
            return data;
        }).collect(Collectors.toList());

        for(TaskFinishReq req: taskFinishReqList) {
            try {
                /** 更新库位及货架绑定 */
                SubTask subTask = crudService.querySubTaskByTaskCode(req.getINSTRUCTION_CODE());
                if(ObjectUtils.isEmpty(subTask)) {
                    continue;
                }

                if(DictId.TaskType.STOCK_IN.equals(subTask.getTaskType())) {
                    // 解绑RCS地标与容器
                    RCSTaskRequest request = RCSTaskRequest.builder()
                            .podCode(subTask.getPodCode())
                            .positionCode(subTask.getStartLoc())
                            .indBind("0")
                            .build();
                    RCSResponse response = RCSUtil.bindPodAndBerth(request);
                    log.info("解锁RCS地标与容器:res[{}]", response);
                }

                Task task = crudService.queryTaskByTaskCode(subTask.getParentTask());
                if(ObjectUtils.isEmpty(task))
                    continue;

                if(subTask.getEndLoc().equals(task.getEndLoc())) {
                    taskService.updateTaskResource(subTask.getTaskCode(), "finish");
                }

                taskService.updateTaskStatus(subTask.getTaskCode(), "finish");
                taskService.notifyTaskExecResult(subTask.getTaskCode(), "finish");
                taskService.executeNextSubTask(req.getINSTRUCTION_CODE());
                taskService.notifyMovingTaskAction(subTask.getTaskCode(), "finish");
            } catch (BusinessException e) {
                log.error("执行下一任务抛出异常:forwardTask[{}]", req.getINSTRUCTION_CODE());
            }
        }

        return dataList;
    }

    @Override
    public Object newLocationGet(GetNewLocationReq getNewLocationReq) {
        String location = TaskServiceImpl.targetLocationMap.get(getNewLocationReq.getINSTRUCTION_CODE());
        if(ObjectUtils.isEmpty(location)) {
            Map<String, Object> q = new HashMap<>();
            q.put("taskCode", getNewLocationReq.getINSTRUCTION_CODE());

            List<Map<String, Object>> orQList = new ArrayList<>();
            Map<String, Object> orQ = new HashMap<>();
            orQ.put("performStatus", Document.parse(String.format("{id: ObjectId(\"%s\")}", DictId.TaskPerformStatus.ISSUED)));
            orQList.add(orQ);

            try {
                SubTask subTask = crudService.findSubTaskOne(q, orQList);
                if(ObjectUtils.isNotEmpty(subTask)) {
                    return subTask.getEndLoc();
                }
                log.error("未找到子任务信息:taskCode[{}]", getNewLocationReq.getINSTRUCTION_CODE());
            } catch (BusinessException e) {
                log.error("获取新货位查询任务发生异常:{}", e);
            }
        }
        return location;
    }

    @Override
    public Object wcsTaskCancel(List<TaskCancelReq> taskCancelReqList) {

        /** 允许取消 */
        List<WCSResponse.TaskCancelRes> resList = taskCancelReqList.stream().map(req -> {
            WCSResponse.TaskCancelRes res = new WCSResponse.TaskCancelRes();
            res.setINSTRUCTION_CODE(req.getINSTRUCTION_CODE());
            res.setSUCCESS(ResultStatus.SUCCESS);
            return res;
        }).collect(Collectors.toList());
        return resList;
    }

    @Override
    public Object wcsTaskError(TaskErrorReq taskErrorReq) {
        Object data = null;
        SubTask subTask = null;
        Task task = null;
        String locCode = null;
        try {
            subTask = crudService.querySubTaskByTaskCode(taskErrorReq.getINSTRUCTION_CODE());
        } catch (BusinessException e) {
            log.error("查询子任务信息抛出异常:exception[{}],taskCode[{}]", e, taskErrorReq.getINSTRUCTION_CODE());
            return null;
        }
        if(ObjectUtils.isEmpty(subTask)) {
            log.error("查询子任务信息不存在:taskCode[{}]", taskErrorReq.getINSTRUCTION_CODE());
            return null;
        }
        task = crudService.queryTaskByTaskCode(subTask.getParentTask());
        if(ObjectUtils.isEmpty(task)) {
            log.error("查询任务信息不存在:taskCode[{}],subTaskCode[{}]", subTask.getParentTask(), subTask.getTaskCode());
            return null;
        }

        /** 查询任务异常回调路径 */
        TaskCallbackInterface callbackInterface = crudService.queryTaskExceptionCallbackInterfaceByBusiness(task.getBusiness());
        if(ObjectUtils.isEmpty(callbackInterface) || ObjectUtils.isEmpty(callbackInterface.getCallbackInterface())) {
            log.error("未找到任务异常回调路径配置:taskCode[{}],business[{}]", task.getTaskCode(), task.getBusiness());
            return null;
        }

        TaskErrorCallbackVO taskErrorCallbackVO = new TaskErrorCallbackVO();
        taskErrorCallbackVO.setTaskCode(task.getTaskCode());

        synchronized (CallbackService.class) {
            task = crudService.queryTaskByTaskCode(subTask.getParentTask());

            if((TaskErrorCode.FETCH_NOTHING.equals(taskErrorReq.getERROR_CODE()) ||
                    TaskErrorCode.FETCH_NOTHING2.equals(taskErrorReq.getERROR_CODE())) &&
                    (DictId.TaskPerformStatus.PERFORM_FAILED.equals(task.getPerformStatus()) ||
                    DictId.TaskPerformStatus.FINISHED.equals(task.getPerformStatus()))) {
                return "NULL";
            }else if((TaskErrorCode.DOUBLE_IN2.equals(taskErrorReq.getERROR_CODE()) ||
                    TaskErrorCode.DOUBLE_IN.equals(taskErrorReq.getERROR_CODE()))) {
                Map<String, Object> q = new HashMap<>();
                q.put("code", subTask.getEndLoc());
                try {
                    subTask = crudService.querySubTaskByTaskCode(taskErrorReq.getINSTRUCTION_CODE());
                    Location location = crudService.findOne(q, Location.class, EntityTemplateId.LOC_TEMPLATE);
                    if(ObjectUtils.isNotEmpty(location) && ObjectUtils.isEmpty(location.getErrMsg()) &&
                            DictId.TaskPerformStatus.PERFORM_FAILED.equals(subTask.getPerformStatus())) {
                        return location.getCode();
                    }
                } catch (BusinessException e) {
                    log.error("查询异常终点库位抛出异常:{}", e);
                }
            }

            switch (taskErrorReq.getERROR_CODE()) {
                case TaskErrorCode.DOUBLE_IN:
                    log.info("双重入库故障:instructionCode[{}],salverId[{}]", taskErrorReq.getINSTRUCTION_CODE(), taskErrorReq.getSALVER_ID());
                    taskErrorCallbackVO.setErrorCode(TaskErrorCode.DOUBLE_IN);
                    data = sendRequest(taskErrorCallbackVO, callbackInterface.getCallbackInterface());
                    locCode = subTask.getEndLoc();
                    break;
                case TaskErrorCode.DOUBLE_IN2:
                    log.info("放深浅有故障:instructionCode[{}],salverId[{}]", taskErrorReq.getINSTRUCTION_CODE(), taskErrorReq.getSALVER_ID());
                    taskErrorCallbackVO.setErrorCode(TaskErrorCode.DOUBLE_IN2);
                    data = sendRequest(taskErrorCallbackVO, callbackInterface.getCallbackInterface());
                    locCode = subTask.getEndLoc();
                    break;
                case TaskErrorCode.FETCH_NOTHING:
                    log.info("取货无箱故障:instructionCode[{}],salverId[{}]", taskErrorReq.getINSTRUCTION_CODE(), taskErrorReq.getSALVER_ID());
                    taskErrorCallbackVO.setErrorCode(TaskErrorCode.FETCH_NOTHING);
                    data = sendRequest(taskErrorCallbackVO, callbackInterface.getCallbackInterface());
                    locCode = subTask.getStartLoc();
                    break;
                case TaskErrorCode.FETCH_NOTHING2:
                    log.info("取深浅有故障:instructionCode[{}],salverId[{}]", taskErrorReq.getINSTRUCTION_CODE(), taskErrorReq.getSALVER_ID());
                    taskErrorCallbackVO.setErrorCode(TaskErrorCode.FETCH_NOTHING2);
                    data = sendRequest(taskErrorCallbackVO, callbackInterface.getCallbackInterface());
                    locCode = subTask.getStartLoc();
                    break;
                default:
                    log.info("未知故障编号:errorCode[{}],instructionCode[{}]", taskErrorReq.getERROR_CODE(), taskErrorReq.getINSTRUCTION_CODE());
            }

            if(ObjectUtils.isNotEmpty(data)) {
                try {
                    updateResource(locCode, taskErrorReq.getERROR_CODE());
                    updateTaskStatus(task.getTaskCode(), subTask.getTaskCode(), data.toString(), taskErrorReq.getERROR_CODE());
                } catch (BusinessException e) {
                    log.error("更新库位资源及任务状态发生异常:{}", e);
                }
            }
        }
        return data;
    }

    public static String sendRequest(TaskErrorCallbackVO callbackVO, String url) {
        String jsonData = JSONObject.toJSONString(callbackVO);
        HttpResult result = HttpClientUtil.getInstance().postJson(url, jsonData);
        if(result.getStatus() == -1) {
            return "";
        }
        BaseResponse baseResponse = JSONObject.parseObject(result.getBody(), BaseResponse.class);
        return baseResponse.getCode() == 1000 ? baseResponse.getData().toString(): "";
    }

    private void updateResource(String locCode, String errorCode) throws BusinessException {
        if(TaskErrorCode.DOUBLE_IN.equals(errorCode)) {
            // 锁定目标库位
            Map<String, Object> q = new HashMap<>();
            Map<String, Object> u = new HashMap<>();
            q.put("code", locCode);
            u.put("lock", true);
            u.put("errMsg", "双重入库");
            long mc = crudService.update(q, u, EntityTemplateId.LOC_TEMPLATE);
            log.info("锁定目标库位:q[{}],u[{}],mc[{}]", q, u, mc);

        }else if(TaskErrorCode.DOUBLE_IN2.equals(errorCode)) {
            Map<String, Object> q = new HashMap<>();
            Map<String, Object> u = new HashMap<>();
            // 锁定目标库位及浅库位
            q.put("code", locCode);
            Location location = crudService.findOne(q, Location.class, EntityTemplateId.LOC_TEMPLATE);
            u.put("lock", true);
            u.put("errMsg", "放深浅有");

            long mc = crudService.update(q, u, EntityTemplateId.LOC_TEMPLATE);
            log.info("锁定目标库位:q[{}],u[{}],mc[{}]", q, u, mc);

            if(ObjectUtils.isNotEmpty(location)) {
                // 查询目标库位对应的浅库位
                q = new HashMap<>();
                q.put("group", location.getGroup());
                q.put("deep", 1);

                location = crudService.findOne(q, Location.class, EntityTemplateId.LOC_TEMPLATE);
                if(ObjectUtils.isNotEmpty(location)) {
                    q = new HashMap<>();
                    q.put("code", location.getCode());
                    mc = crudService.update(q, u, EntityTemplateId.LOC_TEMPLATE);
                    log.info("锁定浅库位:q[{}],u[{}],mc[{}]", q, u, mc);
                }
            }

        }else if(TaskErrorCode.FETCH_NOTHING.equals(errorCode)) {
            // 锁定目标库位
            Map<String, Object> q = new HashMap<>();
            Map<String, Object> u = new HashMap<>();
            q.put("code", locCode);
            u.put("lock", true);
            u.put("errMsg", "取货无箱");
            long mc = crudService.update(q, u, EntityTemplateId.LOC_TEMPLATE);
            log.info("锁定目标库位:q[{}],u[{}],mc[{}]", q, u, mc);
        }else if(TaskErrorCode.FETCH_NOTHING2.equals(errorCode)) {
            Map<String, Object> q = new HashMap<>();
            Map<String, Object> u = new HashMap<>();
            // 锁定目标库位及浅库位
            q.put("code", locCode);
            Location location = crudService.findOne(q, Location.class, EntityTemplateId.LOC_TEMPLATE);
            u.put("lock", true);
            u.put("errMsg", "取深浅有");

            long mc = crudService.update(q, u, EntityTemplateId.LOC_TEMPLATE);
            log.info("锁定目标库位:q[{}],u[{}],mc[{}]", q, u, mc);

            if(ObjectUtils.isNotEmpty(location)) {
                // 查询目标库位对应的浅库位
                q = new HashMap<>();
                q.put("group", location.getGroup());
                q.put("deep", 1);

                location = crudService.findOne(q, Location.class, EntityTemplateId.LOC_TEMPLATE);
                if(ObjectUtils.isNotEmpty(location)) {
                    q = new HashMap<>();
                    q.put("code", location.getCode());
                    mc = crudService.update(q, u, EntityTemplateId.LOC_TEMPLATE);
                    log.info("锁定浅库位:q[{}],u[{}],mc[{}]", q, u, mc);
                }
            }
        }
    }

    private void updateTaskStatus(String parentTaskCode, String taskCode, String locCode, String errorCode) throws BusinessException {
        //设置当前的任务状态为执行失败
        Map<String, Object> q = new HashMap<>();
        Map<String, Object> u = new HashMap<>();
        if(TaskErrorCode.FETCH_NOTHING.equals(errorCode) || TaskErrorCode.FETCH_NOTHING2.equals(errorCode) || "NULL".equals(locCode)) {
            q.put("taskCode", parentTaskCode);
            u.put("performStatus", Document.parse(String.format("{id: ObjectId(\"%s\")}", DictId.TaskPerformStatus.PERFORM_FAILED)));
            crudService.update(q, u, EntityTemplateId.TASK_TEMPLATE);

            // 设置子任务及后置子任务的状态为执行失败
            q.put("taskCode", taskCode);
            crudService.update(q, u, EntityTemplateId.SUB_TASK_TEMPLATE);

            List<SubTask> subTaskList = crudService.querySubTaskListByParentTask(parentTaskCode);
            Map<String, SubTask> taskCodeMap = new HashMap<>();
            for(SubTask subTask: subTaskList) {
                if(ObjectUtils.isNotEmpty(subTask.getForwardTask())) {
                    taskCodeMap.put(subTask.getForwardTask(), subTask);
                }
            }

            u.put("performStatus", Document.parse(String.format("{id: ObjectId(\"%s\")}", DictId.TaskPerformStatus.ISSUE_FAILED)));
            SubTask lastSubTask = taskCodeMap.get(taskCode);
            while(ObjectUtils.isNotEmpty(lastSubTask)) {
                q.put("taskCode", lastSubTask.getTaskCode());
                crudService.update(q, u, EntityTemplateId.SUB_TASK_TEMPLATE);

                lastSubTask = taskCodeMap.get(lastSubTask.getTaskCode());
            }
        }else {
            Task task = crudService.queryTaskByTaskCode(parentTaskCode);
            SubTask subTask = crudService.querySubTaskByTaskCode(taskCode);
            q.put("taskCode", taskCode);
            u.put("endLoc", locCode);
            long mc = crudService.update(q, u, EntityTemplateId.SUB_TASK_TEMPLATE);
            log.info("更新子任务终点:q[{}],u[{}],mc[{}]", q, u, mc);

            if(ObjectUtils.isNotEmpty(subTask) && ObjectUtils.isNotEmpty(task) && subTask.getEndLoc().equals(task.getEndLoc())) {
                q.put("taskCode", parentTaskCode);
                mc = crudService.update(q, u, EntityTemplateId.TASK_TEMPLATE);
                log.info("更新父任务终点:q[{}],u[{}],mc[{}]", q, u, mc);
            }

            q = new HashMap<>();
            u = new HashMap<>();
            q.put("code", locCode);
            u.put("errMsg", "");
            mc = crudService.update(q, u, EntityTemplateId.LOC_TEMPLATE);
            log.info("更新新的目标库位errMsg为空:q[{}],u[{}],mc[{}]", q, u, mc);

            q = new HashMap<>();
            u = new HashMap<>();
            q.put("taskCode", taskCode);
            u.put("performStatus", Document.parse(String.format("{id: ObjectId(\"%s\")}", DictId.TaskPerformStatus.PERFORM_FAILED)));

            mc = crudService.update(q, u, EntityTemplateId.SUB_TASK_TEMPLATE);
            log.info("设置子任务执行状态为执行失败:q[{}],u[{}],mc[{}]", q, u, mc);
        }
    }

    @Override
    public void wcsAgvRasterReqFinish(AgvRasterResult agvRasterResult) {
        if(Integer.valueOf(1).equals(agvRasterResult.getFINISH_STATE())) {
            CallbackService.rasterOpenMap.remove(String.valueOf(agvRasterResult.getAGV_NO()));

        }else if(Integer.valueOf(2).equals(agvRasterResult.getFINISH_STATE())) {
            CallbackService.rasterCloseMap.remove(String.valueOf(agvRasterResult.getAGV_NO()));
            // 请求rcs继续执行任务
            RCSTaskRequest request = RCSTaskRequest.builder()
                    .taskCode(agvTaskMap.get(String.valueOf(agvRasterResult.getAGV_NO())))
                    .build();
            for(int i=0;i<5;++i) {
                try {
                    RCSResponse response = RCSUtil.continueAgvTask(request);
                    log.info("请求RCS继续执行任务结果:request[{}],response[{}]", request, response);
                    if(RCSResponse.SUCCESS.equals(response.getCode()))
                        break;
                } catch (BusinessException e) {
                    log.error("请求RCS继续执行任务失败:request[{}],error[{}]", request, e);
                }
            }
        }
    }

    public void rcsTaskCallback(RCSTaskCallback rcsTaskCallback) {
        SubTask subTask = null;
        try {
            subTask = crudService.querySubTaskByTaskCode(rcsTaskCallback.getTaskCode());
        } catch (BusinessException e) {
            log.error("查询子任务信息抛出异常:{}", e);
        }
        if(ObjectUtils.isEmpty(subTask))
            return;
        Map<String, Object> u = new HashMap<>();
        if(RCSConstant.TaskCallbackMethod.OUTBIN.equals(rcsTaskCallback.getMethod())) {
            if(DictId.TaskType.STOCK_IN.equals(subTask.getTaskType()) && DictId.BotType.CTU.equals(subTask.getRobotType())) {
                // 取出料箱完成
                try {
                    boxTaskService.ctuBoxTakeOutFinish(subTask.getPodCode());
                } catch (BusinessException e) {
                    log.error("ctu离开起点更新料箱交互状态失败:{}", e);
                }
            }

            try {
                // 更新子任务状态
                taskService.updateTaskStatus(subTask.getTaskCode(), "outbin");
            }catch (Exception ex) {
                log.error("更新子任务状态抛出异常:taskCode[{}],method[{}]", subTask.getTaskCode(), "outbin");
            }

        }else if(RCSConstant.TaskCallbackMethod.END.equals(rcsTaskCallback.getMethod())) {
            try {

                if(DictId.TaskType.STOCK_OUT.equals(subTask.getTaskType()) && DictId.BotType.CTU.equals(subTask.getRobotType())) {
                    // 放下料箱完成
                    boxTaskService.ctuOutBoundTaskFinish(subTask.getPodCode());
                }

                Task task = crudService.queryTaskByTaskCode(subTask.getParentTask());
                if(ObjectUtils.isEmpty(task))
                    return;

                if(subTask.getEndLoc().equals(task.getEndLoc())) {
                    taskService.updateTaskResource(rcsTaskCallback.getTaskCode(), "finish");
                }

                taskService.updateTaskStatus(subTask.getTaskCode(), "finish");
                taskService.notifyTaskExecResult(rcsTaskCallback.getTaskCode(), "finish");
                // 执行下一子任务
                taskService.executeNextSubTask(rcsTaskCallback.getTaskCode());
            } catch (BusinessException e) {
                log.error("rcs完成任务回调处理抛出异常:{}", e);
            }
        }else if(RCSConstant.TaskCallbackMethod.PUT_DOWN.equals(rcsTaskCallback.getMethod())) {
            log.info("ctu申请放下料箱:subTaskCode[{}]", subTask.getTaskCode());
            try {
                boxTaskService.ctuApplyPutDownBox(subTask.getPodCode());
            } catch (BusinessException e) {
                log.error("ctu申请放下料箱更新料箱交互状态抛出异常:{}",e);
            }
        }else if(RCSConstant.TaskCallbackMethod.TAKE_OUT.equals(rcsTaskCallback.getMethod())) {
            log.info("ctu申请取出料箱:subTaskCode[{}]", subTask.getTaskCode());
            try {
                boxTaskService.ctuApplyTakeOutBox(subTask.getPodCode());
            } catch (BusinessException e) {
                log.error("ctu申请取出料箱更新料箱交互状态抛出异常:{}",e);
            }
        }else if(RCSConstant.TaskCallbackMethod.CANCEL.equals(rcsTaskCallback.getMethod())) {
            log.info("RCS任务被取消");

        }else if(RCSConstant.TaskCallbackMethod.RASTER1.equals(rcsTaskCallback.getMethod())) {
            // agv到达光栅前
            log.info("agv进入立库前:currentPositionCode[{}]", rcsTaskCallback.getCurrentPositionCode());

            AgvRasterTaskEnum taskEnum = AgvRasterTaskEnum.getByOuterPos(rcsTaskCallback.getCurrentPositionCode());
            if(ObjectUtils.isNotEmpty(taskEnum)) {
                rasterCloseMap.put(rcsTaskCallback.getRobotCode(), taskEnum.getRasterNo());
                agvTaskMap.put(rcsTaskCallback.getRobotCode(), rcsTaskCallback.getTaskCode());
            }
        }else if(RCSConstant.TaskCallbackMethod.RASTER2.equals(rcsTaskCallback.getMethod())) {
            // agv到达光栅后
            log.info("agv离开立库后:currentPositionCode[{}]", rcsTaskCallback.getCurrentPositionCode());

            AgvRasterTaskEnum taskEnum = AgvRasterTaskEnum.getByOuterPos(rcsTaskCallback.getCurrentPositionCode());
            if(ObjectUtils.isNotEmpty(taskEnum)) {
                rasterOpenMap.put(rcsTaskCallback.getRobotCode(), taskEnum.getRasterNo());
            }
        }

    }
}
